<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Student;
use App\Employee;
use Illuminate\Http\Request;

class AdminController extends Controller {

	public function admin(Request $request)
    {
    	$role=$request->session()->get('role');
    	if($role&&$role=='admin'){
    		return view('admin/index',[
               'username'=>$request->session()->get('username'),
               'userid'=>$request->session()->get('userid')
    		]);
    	}else{
    		return redirect("/admin/login");
    	}

        
    }
    
    public function login()
    {
        return view('admin/login');
    }

    public function teacher()
    {
        return view('admin/teacher');
    }
     public function student()
    {
        return view('admin/student');
    }

    // public function salecost()
    // {
    //     return view('admin/salecost');
    // }

    //  public function itsupport();
    // {
    //     return view('admin/login');
    // }

    //  public function inventory();
    // {
    //     return view('admin/inventory');
    // }

    public function signin(Request $request)
    {
	    	 $this->validate($request, [
		          'name' => 'required',
		          'password' => 'required'
	         ]);
            $data = $request->only('name','password');
            $da=Employee::where('employee_name', $data['name'])
		    	  ->where('password', $data['password'])
		    	  ->where('is_admin', '1')
		    	  ->first();
            if($da){
                    $request->session()->put('username',$data['name']);
	                $request->session()->put('role','admin');
	                $request->session()->put('useid',$da['employee_code']);
	                return response()->json(['success' => true, 'msg' => 'signin success']);
            }else{
                return response()->json(['success' => false, 'msg' => 'signin fail']);
            }
    }
}